package com.ruoyi.business.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.business.vo.TRegisterWorkVo;
import com.ruoyi.business.service.ITRegisterWorkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 工作经历Controller
 *
 * @author Tellsea
 * @date 2024-01-17
 */
@Api(tags = "工作经历Controller")
@RestController
@RequestMapping("/business/registerWork")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TRegisterWorkController extends BaseController {

    private final ITRegisterWorkService tRegisterWorkService;

    @ApiOperation("查询工作经历列表")
    @PreAuthorize("@ss.hasPermi('business:registerWork:list')")
    @GetMapping("/list")
    public TableDataInfo<TRegisterWorkVo> list(TRegisterWorkVo entity) {
        return tRegisterWorkService.queryList(entity);
    }

    @ApiOperation("查询工作经历所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(TRegisterWorkVo entity) {
        return AjaxResult.success("查询成功", tRegisterWorkService.queryAll(entity));
    }

    @ApiOperation("导出工作经历列表")
    @PreAuthorize("@ss.hasPermi('business:registerWork:export')")
    @Log(title = "工作经历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRegisterWorkVo entity) {
        List<TRegisterWorkVo> list = tRegisterWorkService.queryAll(entity);
        ExcelUtil<TRegisterWorkVo> util = new ExcelUtil<>(TRegisterWorkVo.class);
        util.exportExcel(response, list, "工作经历数据");
    }

    @ApiOperation("获取工作经历详细信息")
    @PreAuthorize("@ss.hasPermi('business:registerWork:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", tRegisterWorkService.queryById(id));
    }

    @ApiOperation("新增工作经历")
    @PreAuthorize("@ss.hasPermi('business:registerWork:add')")
    @Log(title = "工作经历", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody TRegisterWorkVo entity) {
        return toAjax(tRegisterWorkService.save(entity));
    }

    @ApiOperation("修改工作经历")
    @PreAuthorize("@ss.hasPermi('business:registerWork:edit')")
    @Log(title = "工作经历", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody TRegisterWorkVo entity) {
        return toAjax(tRegisterWorkService.updateById(entity));
    }

    @ApiOperation("删除工作经历")
    @PreAuthorize("@ss.hasPermi('business:registerWork:remove')")
    @Log(title = "工作经历", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tRegisterWorkService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
